package eleanor.ltd.isne.dao.messages.priority;

import java.util.List;

import javax.inject.Inject;

import org.hibernate.Session;
import org.hibernate.criterion.Order;

import eleanor.ltd.isne.entities.messages.priority.MessagePriority;

public class MessagesPriorityDAOImpl implements MessagesPriorityDAO {

	@Inject
    private Session session;

    public boolean save(MessagePriority newMessagePriority) {
            if (newMessagePriority != null) {
                    session.save(newMessagePriority);
                    return true;
            }
            return false;
    }

    public boolean delete(MessagePriority messagePriority) {
            if (messagePriority != null) {
                    session.delete(messagePriority);
                    return true;
            }
            return false;
    }

    public boolean update(MessagePriority messagePriority) {
            if (messagePriority != null) {
                    session.update(messagePriority);
                    return true;
            }
            return false;
    }

    public List<MessagePriority> findAll() {
            return session.createCriteria(MessagePriority.class)
                            .addOrder(Order.asc("name")).list();
    }

    public MessagePriority findByID(Long id) {
            if (id != null) {
                    return (MessagePriority) session.load(MessagePriority.class, id);
            }
            return null;
    }

    public boolean deleteByID(Long id) {
            if (id != null) {
                    MessagePriority m = findByID(id);
                    if (m != null) {
                            session.delete(m);
                            return true;
                    }
                    return false;
            }
            return false;
    }

}
